//
//  StatisticsResultViewController.m
//  CMVRFForIOS
//
//  Created by zhangnorman on 15/5/16.
//  Copyright (c) 2015年 hvacapp. All rights reserved.
//

#import "StatisticsResultViewController.h"
#import <MBProgressHUD.h>


@interface StatisticsResultViewController () {
    MBProgressHUD *HUD;
    NSString *url;
}

@property (nonatomic,strong) UIWebView *webView;

@end

@implementation StatisticsResultViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupViews];
    //[self loadWebData];
    // Do any additional setup after loading the view.
}


#pragma mark - 初始化视图
- (void)setupViews{
    self.title = @"数据统计";
    
    
    UIView *actionView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, kNavigation_Bar_Height)];
    
    UIButton *shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [shareBtn setTitle:@"分享" forState:UIControlStateNormal];
    [shareBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    shareBtn.titleLabel.font = [UIFont systemFontOfSize: kListTitleFontSize];
    shareBtn.frame = CGRectMake(0, 0, 2*kListTitleFontSize, kListTitleFontSize);
    [shareBtn addTarget:self action:@selector(shareButtonClicked) forControlEvents:UIControlEventTouchUpInside];
    [actionView addSubview:shareBtn];
    shareBtn.centerY = kNavigation_Bar_Height/2;
    
    actionView.width = CGRectGetMaxX(shareBtn.frame);
    
    //自定义按钮
    UIBarButtonItem *backBtn = [[UIBarButtonItem alloc] initWithCustomView:actionView];
    self.navigationItem.rightBarButtonItem = backBtn;
    
    //列表
    self.webView = [[UIWebView alloc] initWithFrame:[UIView frameWithOutNav]];
    self.webView.delegate = self;
    self.webView.scalesPageToFit = YES;
    //self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, self.view.height - kNavigation_Bar_Height - kStatus_Bar_Height - KAction_Bar_Height)];
    
}

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    url = [NSString stringWithFormat:@"%@%@?token=%@&sid=%@&tf=%@&tt=%@&rid=%@", HTTP_HOST, HTTP_GET_STATISTICS_RESULTS, [[AccountManager manager]token], self.sid, self.tf, self.tt, self.rid];
    NSURLRequest *request =[NSURLRequest requestWithURL:[NSURL URLWithString:url]];
    [self.view addSubview: self.webView];
    HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    HUD.labelText = @"数据加载中...";
    [self.webView loadRequest:request];
}



- (void)shareButtonClicked {
    
   
}


- (void)webViewDidStartLoad:(UIWebView *)webView {
    
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [HUD setHidden:YES];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    kTipAlert(@"请求数据失败，请重试！");
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
